package app {
	import flash.display.MovieClip;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author hungconcon
	 */
	public class Game extends MovieClip {
		
		
		
		public function Game() {
			super();
			
			radius = Math.round(width / 2);
			bounce = 0.8;
			mass = 50;
			vx = 0;
			xmin = radius;
			xmax = App.screenwid - radius;
			ymax = App.yland - radius;
			bumped = uda = udaswap = pass = swapdep = still = got = 0;
			
			addEventListener(Event.ADDED_TO_STAGE, onCompleteRender);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		public function onCompleteRender(evt:Event):void {
			
			
		}
		public function onEnterFrame(evt:Event):void {
			
			oldx = x;
			oldy = y;
			vy = vy + App.grav;
			y = y + vy;
			x = x + vx;
			
			if (vy > 0) {
				uda ? null : (uda = 1, App.balls.push(t));
				if (y < 250) {
					
					for (var i:int = 0; i < App.rings.length; i++) {
						var reg1:Ring = App.rings[i];
						if (Math.abs(reg1.y - y) < 60 && Math.abs(reg1.x - x) < 60) {
							
							if (t[reg1._name + "pass"] == undefined) {
								t[reg1._name + "pass"] = 0;
							} else if (t[reg1._name + "pass"] == 0) {
								if (hitTest(reg1.z1)) {
									
									t[reg1._name + "pass"] = 1;
									
									udaswap ? null : (udaswap = 1, swapDepths(dep - 20000));
								}
							} else if (t[reg1._name + "pass"] == 1) {
								if (hitTest(reg1.z2)) {
									reg1.got = 1;
									++got;
									reg1.netani = 3;
									// music
									t[reg1._name + "pass"] = 9;
								}
							}
							
						} else {
							t[reg1._name + "pass"] = undefined;
						}
					}
					
				}
			}
			if (vy > 0 && y > 250) {
				if (got > 1) {
					App.ang = App.ang + App.multiringscore[got];
					popmultirings(x, 240, got);
					App.ztititink.start();
					got = 0;
				}
			}
			if (y > ymax) {
				bumped = 1;
				y = ymax;
				//vy <= 2 ? null : ballsfx(vy * 4);
				vy = -0.8 * vy;
				vx = 0.99 * vx;
			}
			if (x < xmin) {
				x = xmin;
				vx = -0.8 * vx;
			} else if (x > xmax) {
				x = xmax;
				vx = -0.8 * vx;
			}
			if (y == ymax) {
				Math.abs(oldx - x) < 1 && Math.abs(oldy - y) < 1 ? (still = 1) : (still = 0);
			}
		}
	
	}

}